package top.lixunda.ecommerce.server.good.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import top.lixunda.commerce.common.core.entity.MessageObject;
import top.lixunda.ecommerce.server.business.BaseController;
import top.lixunda.ecommerce.server.good.api.entity.db.SysGoodActivityDO;
import top.lixunda.ecommerce.server.business.api.entity.dto.PageDTO;
import top.lixunda.ecommerce.server.good.api.entity.vo.SysGoodActivityVO;
import top.lixunda.ecommerce.server.good.api.controller.ISysGoodActivityController;
import top.lixunda.ecommerce.server.good.service.ISysGoodActivityService;

import java.util.List;

/**
 * 活动管理
 *
 * @author Xumda
 * @version time:2020/1/11 11:54
 */
@Slf4j
@RestController
public class SysGoodActivityController extends BaseController implements ISysGoodActivityController {

    private final ISysGoodActivityService sysGoodActivityService;

    @Autowired
    public SysGoodActivityController(ISysGoodActivityService sysGoodActivityService) {
        this.sysGoodActivityService = sysGoodActivityService;
    }

    /**
     * 根据id查询活动信息，可以获取到过期的活动信息
     *
     * @param id 活动id
     * @return 活动信息
     */
    @Override
    public MessageObject<SysGoodActivityVO> queryById(Integer id) {
        SysGoodActivityDO sysGoodActivityDO = sysGoodActivityService.queryById(id);
        SysGoodActivityVO vo = SysGoodActivityVO.fromSysGoodActivityDO(sysGoodActivityDO);
        return getSuccessMessageObject("获取数据成功", vo);
    }

    /**
     * 获取所有可用的活动信息，没有过期，正常状态
     *
     * @return 活动信息列表
     */
    @Override
    public MessageObject<List<SysGoodActivityVO>> queryUseableActivities() {
        List<SysGoodActivityDO> list = sysGoodActivityService.queryUseableActivities();
        List<SysGoodActivityVO> vo = SysGoodActivityVO.fromSysGoodActivityDO(list);
        return getSuccessMessageObject("获取数据成功", vo);
    }

    /**
     * 分页获取所有可用的活动信息，没有过期，正常状态
     *
     * @param pageDTO 分页数据
     * @return 分页的系统活动数据
     */
    @Override
    public MessageObject<IPage<SysGoodActivityVO>> queryUseableActivitiesPage(PageDTO<SysGoodActivityDO, ?> pageDTO) {
        IPage<SysGoodActivityDO> page = sysGoodActivityService.queryUseableActivitiesPage(pageDTO);
        IPage<SysGoodActivityVO> voPage = pageConvert(page, SysGoodActivityVO::fromSysGoodActivityDO);
        return getSuccessMessageObject("获取数据成功", voPage);
    }
}
